export default {
  render(h) {
    // 4. 获取path对应的component
    // let component = null
    // this.$router.$options.routes.forEach(route => {
    //   if (route.path === this.$router.current) {
    //     component = route.component
    //   }
    // })
    // return h(component)
    // 每次更改，都要遍历性能太差

    // 标记当前routerView的深度
    this.$vnode.data.routerView = true
    let depth = 0
    let parent = this.$parent
    while (parent) {
      const vnodeData = parent.$vnode.data
      if (vnodeData) {
        if (vnodeData.routerView) {
          // 说明当前的parent是routerView
          depth++
        }
      }
      parent = parent.$parent
    }

    // 解构出来
    // const { routeMap, current } = this.$router
    // console.log(routeMap, current)
    // 可能并无更新
    // const component = routeMap[current].component || null
    // 根据depth获取component
    let component = null
    const route = this.$router.matched[depth]
    if (route) {
      component = route.component
    }
    return h(component)
  },
}
